#ifndef _UART_H
#define _UART_H

#ifdef __cplusplus
 extern "C" {
#endif 

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include <stdio.h>
#include "main.h"

typedef enum 
{
  COMPC= 0,
  COMGSM = 1,
  COMGPS = 2
} COM_TypeDef;

#define COMn                             3

/**
 * @brief Definition for COM port1, connected to USART3
 */ 
#define COM_DEBUG                       		 	USART3
#define COM_DEBUG_CLK                   	 		RCC_APB1Periph_USART3
#define COM_DEBUG_TX_PIN                 	 	GPIO_Pin_10
#define COM_DEBUG_TX_GPIO_PORT       		GPIOB
#define COM_DEBUG_TX_GPIO_CLK          		RCC_APB2Periph_GPIOB
#define COM_DEBUG_RX_PIN                	 	GPIO_Pin_11
#define COM_DEBUG_RX_GPIO_PORT      		GPIOB
#define COM_DEBUG_RX_GPIO_CLK        		RCC_APB2Periph_GPIOB
#define COM_DEBUG_IRQn                  	 		USART3_IRQn

/**
 * @brief Definition for COM port GPS, connected to USART2
 */ 
 #define UART_GPS							COM_GPS
#define COM_GPS								USART2
#define COM_GPS_CLK                    			RCC_APB1Periph_USART2
#define COM_GPS_TX_PIN                 			GPIO_Pin_2
#define COM_GPS_TX_GPIO_PORT      			GPIOA
#define COM_GPS_TX_GPIO_CLK        			RCC_APB2Periph_GPIOA
#define COM_GPS_RX_PIN                			GPIO_Pin_3
#define COM_GPS_RX_GPIO_PORT      			GPIOA
#define COM_GPS_RX_GPIO_CLK        			RCC_APB2Periph_GPIOA
#define COM_GPS_IRQn                   			USART2_IRQn

/**
 * @brief Definition for COM port GSM, connected to USART1
 */ 
 #define UART_GSM							COM_GSM	
#define COM_GSM							USART1
#define COM_GSM_CLK                    			RCC_APB2Periph_USART1
#define COM_GSM_TX_PIN                 			GPIO_Pin_9
#define COM_GSM_TX_GPIO_PORT      			GPIOA
#define COM_GSM_TX_GPIO_CLK        			RCC_APB2Periph_GPIOA
#define COM_GSM_RX_PIN                			GPIO_Pin_10
#define COM_GSM_RX_GPIO_PORT      			GPIOA
#define COM_GSM_RX_GPIO_CLK        			RCC_APB2Periph_GPIOA
#define COM_GSM_IRQn                   			USART1_IRQn

void UARTInit(void);
void UART_DEBUG_ISR(void);
void UARTSendByte(USART_TypeDef* USARTx, uint8_t Data);
uint8_t UARTReceiveByte(USART_TypeDef* USARTx);

void UART_DEBUG_SendByte(uint8_t data);
void UART_DEBUG_SendString(uint8_t *data);
uint8_t UART_DEBUG_ReceivedByte(void);
void UART_DEBUG_ReceivedString(uint8_t *data_buff, uint8_t data_len);
uint8_t UART_DEBUG_RXAvailable(void);
void UART_DEBUG_RXFlush(void);

#endif

